package com.xxxx.server.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xxxx.server.mapper.DepartmentMapper;
import com.xxxx.server.pojo.Department;
import com.xxxx.server.pojo.RespBean;
import com.xxxx.server.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;


/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zhoubin
 */
@Service
public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Department> implements IDepartmentService {

    @Autowired
    private DepartmentMapper departmentMapper;

    @Override
    public List<Department> selectDepartmentAll() {

        return departmentMapper.selectDepartmentAll(-1);
    }

    @Override
    public RespBean addDepartment(Department department) {
        if (departmentMapper.addDepartment(department) > 0){
            return RespBean.success("添加成功",department);
        }
        return RespBean.error("添加失败");
    }

    @Override
    public RespBean deleteDepartment(Integer id) {
        int rows = departmentMapper.deleteDepartment(id);
        if (rows == 1){
            return RespBean.success("删除成功");
        }

        return RespBean.error("删除失败,此部门下还有其他数据！");

    }
}
